package handlers

import (
	"github.com/gin-gonic/gin"
	"strconv"
	"xiao-hong-shu-app/models"
)

func Add(c *gin.Context) {
	title := c.PostForm("title")
	content := c.PostForm("content")
	author := c.PostForm("author")
	if title == "" || content == "" || author == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不能为空",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
func Up(c *gin.Context) {

}
func List(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	size, _ := strconv.Atoi(c.Query("size"))
	offset := (page - 1) * size

}
func Detail(c *gin.Context) {
	var article []models.Article
	title := c.PostForm("title")
	content := c.PostForm("content")
	author := c.PostForm("author")
	data := models.Article{
		Title:   title,
		Content: content,
		Author:  author,
	}
	err := models.DB.Find(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "查询失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"data": a,
	})
	return
}
